<?php
/**
 * Description: 单题突破\名师精批\申论套题收藏
 * User: lizhen
 * Date: 14/10/16
 * Time: 16:03
 */

class SetCollectShenlun implements iController {


    public function output($queryArgs) {
        global $cmsdb,$uddb;

        if (validateUser($queryArgs) !== 1)
            return genOutput(1000);

        if (empty($queryArgs['exercise_id']) || empty($queryArgs['question_id']) || !is_numeric($queryArgs['question_id']) ||
            empty($queryArgs['type']))
            return genOutput(1000);

        //获取题目信息
        $qInfo = $cmsdb->getRow('SELECT * FROM `original_ztk_shenlun_questions` WHERE `id`=:qid',
            array(':qid' => $queryArgs['question_id']));
        if (empty($qInfo))
            return genOutput(1000);

        $sql = "select id from history_primary_question_review where user_id=:uid and exercise_id=:eid  and question_id=:qid";
        $qExists = $uddb->getVar($sql,
            [
                ':uid' => $queryArgs['user_id'],
                ':eid' => $queryArgs['exercise_id'],
                ':qid' => $queryArgs['question_id']
            ]);

        if (!empty($qExists)) {

            if ($queryArgs['type'] == 'collect') {

                $status = $uddb->update('history_primary_question_review', ['is_collected' => 1], ['id' => $qExists]);

            }else if ($queryArgs['type'] == 'cancel') {

                $status = $uddb->update('history_primary_question_review', ['is_collected' => 2], ['id' => $qExists]);

            }

            if ($status)    return genOutput(1);
        }
        return genOutput(1000);
    }
}